import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * The Class VendingMachineTest.
 */
public class VendingMachineTest {

	VendingMachine myVendingMachine;
	VendingMachineItem sunChips;
	VendingMachineItem donut;
		
	/**
	 * Set up the Test Run by creating Objects.
	 * @throws Exception the exception
	 * 
	 */
	@Before
	public void setUp() throws Exception {
		myVendingMachine = new VendingMachine();
		sunChips = new VendingMachineItem("Sun Chips", 2.00);
		donut = new VendingMachineItem("Donut", 2.50);
	}

	/**
	 * Tear down.
	 *
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test add item for Correct Slot.
	 * Postcondition: Test run will be true if the item's slot and the expected slot for the item are same.
	 */
	@Test public void testAddItem() {
		myVendingMachine.addItem(sunChips, VendingMachine.C_CODE);
		assertEquals(sunChips,myVendingMachine.getItem(VendingMachine.C_CODE));
	}

	
	/**
	 * Test add item for wrong item in the specified slot.
	 * Postcondition: Test run will be false if the item's slot and the expected slot for the item are different.
	 */
	@Test public void testAddItem_Wrong_Item() {
		myVendingMachine.addItem(donut, VendingMachine.C_CODE);
		assertEquals(sunChips,myVendingMachine.getItem(VendingMachine.C_CODE));
	}

	/**
	 * Test add item for already occupied slot.
	 * Postcondition: Test run will be false if the item's slot is occupied by other item.
	 * @throws VendingMachineException If trying to add item in a non-empty slot.
	 */
	@Test(expected=VendingMachineException.class)
	public void testAddItem_Wrong_Slot() {
		myVendingMachine.addItem(donut, VendingMachine.C_CODE);
		try{
			myVendingMachine.addItem(sunChips, VendingMachine.C_CODE);
		}catch(VendingMachineException e){
			e = new VendingMachineException("testAddItem_Wrong_Slot(): Slot is already occupied");
			System.out.println(e.getMessage());
		}
	}

	
	
	/**
	 * Test remove item from a slot.
	 * Postcondition: Test run will be true if the item removed is present in the slot mentioned.
	 * @throws VendingMachineException If trying to remove item which is not present in the code.
	 */
	@Test 
	public void testRemoveItem() {
		myVendingMachine.addItem(donut, VendingMachine.A_CODE);
		assertEquals(donut, myVendingMachine.removeItem(VendingMachine.A_CODE));
 	}
	
	/**
	 * Test remove item from an empty slot.
	 * Postcondition: Test run will be true if the slot mentioned is empty.
	 * @throws VendingMachineException If trying to remove item which is not present in the code.
	 */
	@Test(expected=VendingMachineException.class) 
	public void testRemoveItem_EmptySlot() {
		//myVendingMachine.addItem(donut, VendingMachine.A_CODE);
		assertEquals(donut, myVendingMachine.removeItem(VendingMachine.A_CODE));
 	}

	/**
	 * Test insert money.
	 */
	@Test
	public void testInsertMoney() {
	}

	/**
	 * Test get balance.
	 */
	@Test
	public void testGetBalance() {
	}

	/**
	 * Test make purchase.
	 */
	@Test
	public void testMakePurchase() {
	}

	/**
	 * Test return change.
	 */
	@Test
	public void testReturnChange() {
	}

}
